#include <syscall.h>

int uread (int fd,uint8_t *buffer,uint32_t length){
	nomalloc_spb.scp_magic = SCP_MAGIC;
	nomalloc_spb.function_id = SC_READ;
	nomalloc_spb.parameters[0] = (uint32_t) fd;
	nomalloc_spb.parameters[1] = (uint32_t) buffer;
	nomalloc_spb.parameters[2] = length;
	syscall(&nomalloc_spb);
	errno = nomalloc_spb.errno;
	return (int)nomalloc_spb.result;
}

int uwrite(int fd,uint8_t *buffer,uint32_t length){
	nomalloc_spb.scp_magic = SCP_MAGIC;
	nomalloc_spb.function_id = SC_WRITE;
	nomalloc_spb.parameters[0] = (uint32_t) fd;
	nomalloc_spb.parameters[1] = (uint32_t) buffer;
	nomalloc_spb.parameters[2] = length;
	syscall(&nomalloc_spb);
	errno = nomalloc_spb.errno;
	return (int)nomalloc_spb.result;
}

int useek (int fd,uint32_t position, uint8_t whence){	
	nomalloc_spb.scp_magic = SCP_MAGIC;
	nomalloc_spb.function_id = SC_SEEK;
	nomalloc_spb.parameters[0] = (uint32_t) fd;
	nomalloc_spb.parameters[1] = position;
	nomalloc_spb.parameters[2] = (uint32_t) whence;
	syscall(&nomalloc_spb);
	errno = nomalloc_spb.errno;
	return (int)nomalloc_spb.result;
}

int umkloop(uint32_t buffersize){
	nomalloc_spb.scp_magic = SCP_MAGIC;
	nomalloc_spb.function_id = SC_MKLOOP;
	nomalloc_spb.parameters[0] = buffersize;
	syscall(&nomalloc_spb);
	errno = nomalloc_spb.errno;
	return (int)nomalloc_spb.result;
}

int u_umount (char *mp,char *type){
	nomalloc_spb.scp_magic = SCP_MAGIC;
	nomalloc_spb.function_id = SC_UMOUNT;
	nomalloc_spb.parameters[0] = (uint32_t)mp;
	nomalloc_spb.parameters[1] = (uint32_t)type;
	syscall(&nomalloc_spb);
	errno = nomalloc_spb.errno;
	return (int)nomalloc_spb.result;
}

int u_mount (char *mp,char *dev,char *type){
	nomalloc_spb.scp_magic = SCP_MAGIC;
	nomalloc_spb.function_id = SC_MOUNT;
	nomalloc_spb.parameters[0] = (uint32_t)mp;
	nomalloc_spb.parameters[1] = (uint32_t)dev;
	nomalloc_spb.parameters[2] = (uint32_t)type;
	syscall(&nomalloc_spb);
	errno = nomalloc_spb.errno;
	return (int)nomalloc_spb.result;
}

int uopen (char *name,uint32_t flags,uint32_t mode){
	nomalloc_spb.scp_magic = SCP_MAGIC;
	nomalloc_spb.function_id = SC_OPEN;
	nomalloc_spb.parameters[0] = (uint32_t) name;
	nomalloc_spb.parameters[1] = flags;
	nomalloc_spb.parameters[2] = mode;
	syscall(&nomalloc_spb);
	errno = nomalloc_spb.errno;
	return (int)nomalloc_spb.result;
}

int	uavail(int fd){
	nomalloc_spb.scp_magic = SCP_MAGIC;
	nomalloc_spb.function_id = SC_AVAIL;
	nomalloc_spb.parameters[0] = (uint32_t) fd;
	syscall(&nomalloc_spb);
	errno = nomalloc_spb.errno;
	return (int)nomalloc_spb.result;
}

int	uclose(int fd){
	nomalloc_spb.scp_magic = SCP_MAGIC;
	nomalloc_spb.function_id = SC_CLOSE;
	nomalloc_spb.parameters[0] = (uint32_t) fd;
	syscall(&nomalloc_spb);
	errno = nomalloc_spb.errno;
	return (int)nomalloc_spb.result;
}

int uchdir (char *name){
	nomalloc_spb.scp_magic = SCP_MAGIC;
	nomalloc_spb.function_id = SC_CHDIR;
	nomalloc_spb.parameters[0] = (uint32_t) name;
	syscall(&nomalloc_spb);
	errno = nomalloc_spb.errno;
	return (int)nomalloc_spb.result;
}

int umkdir (char *name){
	nomalloc_spb.scp_magic = SCP_MAGIC;
	nomalloc_spb.function_id = SC_MKDIR;
	nomalloc_spb.parameters[0] = (uint32_t) name;
	syscall(&nomalloc_spb);
	errno = nomalloc_spb.errno;
	return (int)nomalloc_spb.result;
}